local newc = require("newc")

---@type table<table,table>
local methods = {}

---class 定义
---@generic T
---@param base T
---@return T
return function(base)
    local info = debug.getinfo(2, "S")
    local file = info.source

    ---@class source @class类型
    local source = newc(file, "source")
    source.__base = base
    source.__type = 'class'

    local virtual = newc(file, "virtual")
    methods[source] = virtual

    if base then
        local supermeta = newc(file, "supermeta")
        supermeta.__index = methods[base]
        setmetatable(virtual, supermeta)
    end

    source.new = function(...)
        local obj = {
            __base = source,
            __type = 'object',
        }
        setmetatable(obj, {
            __index = virtual
        })
        obj:ctor(...)
        return obj
    end

    local meta = newc(file, "meta")
    meta.__index = virtual
    meta.__newindex = virtual
    setmetatable(source, meta)
    return source
end
